﻿using Microsoft.AspNetCore.Builder;
using My.Framework.AspNetCore;
using My.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using My.Core.DynamicProxy;
using My.Core.Util;
using Scrutor;

namespace My.Core.IOC
{
    /// <summary>
    /// 程序启动器 - 自动化注册服务
    /// </summary>
    public class CoreAutoRegisterIOCStartup : StartupModule<CoreAutoRegisterIOCStartup>
    {
        /// <summary>
        /// 程序启动器
        /// </summary>
        public CoreAutoRegisterIOCStartup() => Order = -999;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="webApplicationBuilder"></param>
        public override void ConfigureServices(WebApplicationBuilder webApplicationBuilder)
        {
            // 扫描服务自动化注册
            if (AssemblyUtil.GetAssemblyList().ToList() == null) return;
            var assemblyList = AssemblyUtil.GetAssemblyList().ToList();
            DynamicProxyClass.Start(webApplicationBuilder.Services, assemblyList, RegistrationStrategy.Replace());
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="webApplication"></param>
        public override void Configure(WebApplication webApplication)
        {

        }

    }
}
